home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr28 / dats520.zip / DATECHK.BAS next >
BASIC Source File  |  1995-02-13  |  11KB  |  397 lines

  1. DEFINT A-Z
  2.  
  3. 'Declare Routines
  4.  
  5. 'Checks DataFile
  6. DECLARE SUB HolidayCheck ()
  7.  
  8. 'Routine to perform the daily batch file (if it is a different day)
  9. DECLARE SUB DayCheck ()
  10.  
  11. 'Routine to perform the weekly batch file if days since the last run
  12. 'is > 6, or if DayOfWeek = 0 (Sunday)
  13. DECLARE SUB WeekCheck ()
  14.  
  15. 'Routine to perform the monthly batch file.
  16. DECLARE SUB MonthCheck ()
  17.  
  18. 'Routine to perform the yearly batch file.
  19. DECLARE SUB YearCheck ()
  20.  
  21. 'Routine to perform the user batch file.
  22. DECLARE SUB UserCheck ()
  23.  
  24. 'Support for the User Batch Routine.
  25. DECLARE SUB UserDaysRead ()
  26. DECLARE SUB ConfigUserRec ()
  27. DECLARE SUB WriteUser (User%, Accum%)
  28.  
  29. 'Routine to Write dat$ (a date in the form "MM-DD-YYYY") in the first 2 bytes
  30. 'of the record file
  31. DECLARE SUB RecordDate (Dat$, File$, Locat)
  32.  
  33. 'Routine that handles the init process
  34. DECLARE SUB InitDateCheck ()
  35.  
  36. 'If running under NDOS, this routine interfaces with NDOS to describe the
  37. 'DateCheck files
  38. DECLARE SUB Describe (Fle$, des$)
  39.  
  40. 'Needed to check for New DataFile
  41. DECLARE FUNCTION NewCheck (File$)
  42.  
  43. 'Determines whether or not a file exists.  0 for No, -1 for Yes
  44. DECLARE FUNCTION Exist% (File$)
  45.  
  46. 'Determines the name of the file currently in place as the Command Processer
  47. DECLARE FUNCTION Intrptr$ ()
  48.  
  49. 'Translates a 2-byte Date string back to "MM-DD-YYYY" format
  50. DECLARE FUNCTION TranslateDate$ (DateString$)
  51.  
  52. 'Declare Constants
  53. 'Program Conditions
  54. CONST False = 0, True = NOT False
  55.  
  56. 'Program Qualities  NOTE: These usually CHANGE from version to version.
  57. CONST Version = "5.20"
  58.  
  59. 'Filename and Description constants
  60. CONST PrShellForDescrip = "NDOS.COM"
  61. CONST OldDataFile = "DATECHK.REC"
  62. CONST DataFile = "DATECHK.DAT", ProgramName = "DATECHK.EXE"
  63. CONST DRFDes = "Data file"
  64. CONST PFDes = "Daily, Weekly and Monthly Maint. Manager"
  65. CONST DailyBatch = "DAILY.BAT", DailyDes = "Daily Maintenance"
  66. CONST WeeklyBatch = "WEEKLY.BAT", WeeklyDes = "Weekly Maintenance"
  67. CONST MonthlyBatch = "MONTHLY.BAT", MonthlyDes = "Monthly Maintenance"
  68. CONST UserBatch = "USER.BAT", UserDes = "User Maintenance"
  69. CONST YearlyBatch = "YEARLY.BAT", YearlyDes = "Yearly Maintenance"
  70.  
  71. 'Command Line Options
  72. CONST CheckOption = "/CHECK"
  73. CONST AutoOption = "/AUTO"
  74. CONST ConfigOption = "/CONFIG"
  75.  
  76. 'Type Definitions
  77. TYPE HolRec
  78.    Date AS STRING * 2
  79.    Text AS STRING * 60
  80. END TYPE
  81.  
  82. 'Declare Arrays and Shared Variables
  83. DIM SHARED Byte(3) AS STRING * 1, RWByte AS STRING * 1, Record AS HolRec
  84. DIM SHARED Flag%(4), Dates$(2), UserDays, UserAccum
  85. DIM SHARED StoreDate AS STRING * 2
  86. 'Determine whether or not Describe may be used
  87. IF Intrptr$ = PrShellForDescrip THEN Flag%(1) = True
  88.  
  89. 'Determine whether or not the user wants to be prompted
  90. IF COMMAND$ = AutoOption THEN Flag%(4) = True
  91.  
  92. Flag%(3) = False
  93. Dates$(1) = DATE$
  94.  
  95. InitDateCheck
  96.  
  97. IF COMMAND$ = ConfigOption THEN
  98.    ConfigUserRec
  99.    END
  100. END IF
  101.  
  102. 'Check for whether or not the batch files are due to be run
  103. PRINT "Date Check version "; Version; ".  Checking for due maintenance..."
  104. IF Dates$(1) <> Dates$(2) OR MID$(COMMAND$, 1, 6) = CheckOption THEN
  105.    CALL RecordDate(Dates$(1), DataFile, 1)
  106.    DayCheck
  107.    WeekCheck
  108.    MonthCheck
  109.    YearCheck
  110.    UserCheck
  111.    HolidayCheck
  112. END IF
  113. CLOSE
  114. END
  115.  
  116. SUB ConfigUserRec ()
  117. INPUT "Enter the number of days to check for the USER.BAT intervention [0]:", User
  118. IF User = 0 THEN
  119.    Fil% = FREEFILE
  120.    OPEN DataFile FOR BINARY AS Fil%
  121.    RWByte = CHR$(0)
  122.    FOR x = 3 TO 5
  123.       PUT #1, x, RWByte
  124.    NEXT
  125.    CLOSE Fil%
  126.    EXIT SUB
  127. ELSE
  128.    CALL WriteUser(User, 0)
  129. END IF
  130. END SUB
  131.  
  132. SUB DayCheck ()
  133.    IF Flag%(4) = False THEN
  134.       PRINT "Daily Maintenance is due... Execute " + DailyBatch + "? (Y/n)"
  135.       Choi$ = INPUT$(1)
  136.    END IF
  137.    IF UCASE$(Choi$) <> "N" THEN
  138.       PRINT "Performing Daily Maintenance..."
  139.       IF NOT Exist%(DailyBatch) THEN
  140.          PRINT "No " + DailyBatch + "... Skipping..."
  141.       ELSE
  142.          IF Flag%(1) = True THEN
  143.             Describe DailyBatch, DailyDes
  144.          END IF
  145.          SHELL DailyBatch
  146.       END IF
  147.    ELSE
  148.       PRINT "Skipping " + DailyBatch + "..."
  149.    END IF
  150. END SUB
  151.  
  152. SUB Describe (Fle$, DeSTR$)
  153.    SHELL "describe " + Fle$ + " " + CHR$(34) + DeSTR$ + CHR$(34)
  154. END SUB
  155.  
  156. FUNCTION Exist% (File$)
  157.    ON ERROR RESUME NEXT
  158.    Handle% = FREEFILE
  159. 10 OPEN File$ FOR INPUT AS Handle%
  160.    IF ERL = 10 THEN
  161.       Flag%(2) = True
  162.    END IF
  163.    ON ERROR GOTO 0
  164.    IF Flag%(2) = False THEN
  165.       Exist% = True
  166.    ELSE
  167.       Exist% = False
  168.    END IF
  169.    Flag%(2) = False
  170.    CLOSE Handle%
  171. END FUNCTION
  172.  
  173. STATIC SUB HolidayCheck ()
  174.    Fil% = FREEFILE
  175.    OPEN DataFile FOR BINARY AS Fil%
  176.    DO
  177.       Numb% = Locat% * 62 + 6
  178.       GET Fil%, Numb%, Record
  179.       TestDate$ = TranslateDate$(Record.Date)
  180.       IF (MONTH(DATEVALUE(Dates$(1))) = MONTH(DATEVALUE(TestDate$))) AND (DAY(DATEVALUE(Dates$(1))) = DAY(DATEVALUE(TestDate$))) THEN
  181.          PRINT
  182.          PRINT Record.Text
  183.          BEEP
  184.          PRINT "Press any key to continue"
  185.          Dummy$ = INPUT$(1)
  186.       END IF
  187.       Locat% = Locat% + 1
  188.    LOOP WHILE Numb% < LOF(Fil%)
  189.    CLOSE Fil%
  190. END SUB
  191.  
  192. SUB InitDateCheck ()
  193.    IF Exist(OldDataFile) OR NewCheck(DataFile) THEN
  194.       IF Exist(OldDataFile) THEN
  195.          KILL OldDataFile
  196.       END IF
  197.       CALL RecordDate(Dates$(1), DataFile, 1)
  198.       PRINT "This is either an upgrade, or a new installation of Date Check!"
  199.       PRINT "You will be prompted to enter a value for the number of days to"
  200.       PRINT "wait between USER.BAT checks.  If you do not wish to use the"
  201.       PRINT "'User Check' option, just enter 0.  NOTE: You can change your mind"
  202.       PRINT "later by entering /CONFIG on the command line"
  203.       ConfigUserRec
  204.       Flag%(3) = True
  205.    ELSE
  206.       CLOSE Fil%
  207.    END IF
  208.    IF Flag%(1) = True THEN
  209.       Describe DataFile, DRFDes
  210.       Describe ProgramName, PFDes
  211.       IF Flag%(3) = True THEN
  212.          END
  213.       END IF
  214.    END IF
  215.    Fil% = FREEFILE
  216.    OPEN DataFile FOR BINARY AS Fil%
  217.    GET Fil%, 1, StoreDate
  218.    Dates$(2) = TranslateDate$(StoreDate)
  219.    CLOSE Fil%
  220.    UserDaysRead
  221. END SUB
  222.  
  223. FUNCTION Intrptr$ ()
  224.    Interpreter$ = ENVIRON$("COMSPEC")
  225.    FOR x = LEN(Interpreter$) TO 1 STEP -1
  226.       Check$ = MID$(Interpreter$, x, 1)
  227.       IF Check$ = "\" THEN EXIT FOR
  228.       Temp$ = Check$ + Temp$
  229.    NEXT
  230.    Intrptr$ = UCASE$(Temp$)
  231. END FUNCTION
  232.  
  233. SUB MonthCheck ()
  234.    IF MID$(Dates$(1), 1, 2) <> MID$(Dates$(2), 1, 2) OR COMMAND$ = CheckOption THEN
  235.       IF Flag%(4) = False THEN
  236.          PRINT "Monthly Maintenance is due... Execute " + MonthlyBatch + "? (Y/n)"
  237.          Choi$ = INPUT$(1)
  238.       END IF
  239.       IF UCASE$(Choi$) <> "N" THEN
  240.          PRINT "Performing Monthly Maintenance..."
  241.          IF NOT Exist%(MonthlyBatch) THEN
  242.             PRINT "No " + MonthlyBatch + "... Skipping..."
  243.          ELSE
  244.             IF Flag%(1) = True THEN
  245.                Describe MonthlyBatch, MonthlyDes
  246.             END IF
  247.             SHELL MonthlyBatch
  248.          END IF
  249.       ELSE
  250.          PRINT "Skipping " + MonthlyBatch + "..."
  251.       END IF
  252.    END IF
  253. END SUB
  254.  
  255. FUNCTION NewCheck (File$)
  256.    Fi% = FREEFILE
  257.    OPEN File$ FOR RANDOM AS Fi% LEN = 62
  258.    GET Fi%, 1, Record
  259.    IF Record.Date = SPACE$(2) THEN
  260.       NewCheck = True
  261.    ELSE
  262.       NewCheck = False
  263.    END IF
  264.    CLOSE Fi%
  265. END FUNCTION
  266.  
  267. SUB RecordDate (Dat$, File$, Locat)
  268.    Fil% = FREEFILE
  269.    OPEN File$ FOR BINARY AS Fil%
  270.       Mo% = MONTH(DATEVALUE(Dat$))
  271.       Da% = DAY(DATEVALUE(Dat$))
  272.       Yr% = YEAR(DATEVALUE(Dat$)) - 1980
  273.       Byte(1) = CHR$(Mo% * 16 + (Da% AND 30) / 2)
  274.       Byte(2) = CHR$((Da% AND 1) * 128 + Yr%)
  275.       FOR x = 1 TO 2
  276.          PUT #1, x - 1 + Locat, Byte(x)
  277.       NEXT
  278.    CLOSE Fil%
  279. END SUB
  280.  
  281. FUNCTION TranslateDate$ (DateString$)
  282.    TotASC$ = ""
  283.    DIM Calc(2) AS INTEGER
  284.    FOR x = 1 TO LEN(DateString$)
  285.       Calc(x) = ASC(MID$(DateString$, x, 1))
  286.    NEXT
  287.    TranslateDate$ = FORMAT$(DATESERIAL(((Calc(2) AND 127) + 1980), ((Calc(1) AND 240) / 16), ((Calc(1) AND 15) * 2 + (Calc(2) AND 128) / 128)), "MM/DD/YYYY")
  288. END FUNCTION
  289.  
  290. SUB UserCheck ()
  291.    DayCount = DATEVALUE(Dates$(1)) - DATEVALUE(Dates$(2))
  292.    IF (DayCount + UserAccum >= UserDays OR COMMAND$ = CheckOption) AND UserDays > 0 THEN
  293.       IF Flag%(4) = False THEN
  294.          PRINT "User Interval ("; UserDays; " Days) has been exceeded... Execute " + UserBatch + "? (Y/n)"
  295.          Choi$ = INPUT$(1)
  296.       END IF
  297.       IF UCASE$(Choi$) <> "N" THEN
  298.          PRINT "Performing User Maintenance..."
  299.          IF NOT Exist%(UserBatch) THEN
  300.             PRINT "No " + UserBatch + "... Skipping..."
  301.          ELSE
  302.             IF Flag%(1) = True THEN
  303.                Describe UserBatch, UserDes
  304.             END IF
  305.             SHELL UserBatch
  306.          END IF
  307.       ELSE
  308.          PRINT "Skipping " + UserBatch + "..."
  309.       END IF
  310.       CALL WriteUser(UserDays, 0)
  311.    ELSE
  312.       IF UserDays > 0 THEN
  313.          CALL WriteUser(UserDays, UserAccum + DayCount)
  314.       END IF
  315.    END IF
  316. END SUB
  317.  
  318. SUB UserDaysRead ()
  319.    TotASC$ = ""
  320.    Fil% = FREEFILE
  321.    DIM Calc(3) AS INTEGER
  322.    OPEN DataFile FOR BINARY AS Fil%
  323.    FOR x = 3 TO 5
  324.       GET Fil%, x, Z$
  325.       IF Z$ = "" THEN
  326.          UserDays = 0
  327.          UserAccum = 0
  328.          EXIT FOR
  329.       END IF
  330.       Calc(x - 2) = ASC(Z$)
  331.    NEXT
  332.    UserDays = Calc(1) * 2 + (Calc(2) AND 128) / 128
  333.    UserAccum = (Calc(2) AND 127) * 4 + (Calc(3) AND 192) / 64
  334.    'Notice: Bits 19-24 are UNUSED!
  335.    CLOSE Fil%
  336. END SUB
  337.  
  338. SUB WeekCheck ()
  339.    DayCount = DATEVALUE(Dates$(1)) - DATEVALUE(Dates$(2))
  340.    StartWeekDay = WEEKDAY(DATEVALUE(Dates$(1)))
  341.    EndWeekDay = WEEKDAY(DATEVALUE(Dates$(2)))
  342.    IF EndWeekDay > StartWeekDay OR DayCount > 6 OR COMMAND$ = CheckOption THEN
  343.       IF Flag%(4) = False THEN
  344.          PRINT "Weekly Maintenance is due... Execute " + WeeklyBatch + "? (Y/n)"
  345.          Choi$ = INPUT$(1)
  346.       END IF
  347.       IF UCASE$(Choi$) <> "N" THEN
  348.          PRINT "Performing Weekly Maintenance..."
  349.          IF NOT Exist%(WeeklyBatch) THEN
  350.             PRINT "No " + WeeklyBatch + "... Skipping..."
  351.          ELSE
  352.             IF Flag%(1) = True THEN
  353.                Describe WeeklyBatch, WeeklyDes
  354.             END IF
  355.             SHELL WeeklyBatch
  356.          END IF
  357.       ELSE
  358.          PRINT "Skipping " + WeeklyBatch + "..."
  359.       END IF
  360.    END IF
  361. END SUB
  362.  
  363. SUB WriteUser (User, Accum)
  364.    Fil% = FREEFILE
  365.    OPEN DataFile FOR BINARY AS Fil%
  366.    Byte(1) = CHR$((User AND 510) / 2)
  367.    Byte(2) = CHR$((User AND 1) * 128 + (Accum AND 508) / 4)
  368.    Byte(3) = CHR$((Accum AND 3) * 64)
  369.    FOR x = 1 TO 3
  370.       PUT #1, x + 2, Byte(x)
  371.    NEXT
  372.    CLOSE Fil%
  373. END SUB
  374.  
  375. SUB YearCheck ()
  376.    IF YEAR(DATEVALUE(Dates$(1))) <> YEAR(DATEVALUE(Dates$(2))) OR COMMAND$ = CheckOption THEN
  377.       IF Flag%(4) = False THEN
  378.          PRINT "Yearly Maintenance is due... Execute " + YearlyBatch + "? (Y/n)"
  379.          Choi$ = INPUT$(1)
  380.       END IF
  381.       IF UCASE$(Choi$) <> "N" THEN
  382.          PRINT "Performing Yearly Maintenance..."
  383.          IF NOT Exist%(YearlyBatch) THEN
  384.             PRINT "No " + YearlyBatch + "... Skipping..."
  385.          ELSE
  386.             IF Flag%(1) = True THEN
  387.                Describe YearlyBatch, YearlyDes
  388.             END IF
  389.             SHELL YearlyBatch
  390.          END IF
  391.       ELSE
  392.          PRINT "Skipping " + YearlyBatch + "..."
  393.       END IF
  394.    END IF
  395. END SUB
  396.  
  397.